package cn.wildfirechat.message;

import android.os.Parcel;

import cn.wildfirechat.message.core.ContentTag;
import cn.wildfirechat.message.core.MessagePayload;
import cn.wildfirechat.message.core.PersistFlag;

import static cn.wildfirechat.message.core.MessageContentType.ContentType_UserCard;

/**
 * Create by HEKE, 2019/9/23 14:21
 * TODO 用户名片信息类型
 */
@ContentTag(type = ContentType_UserCard, flag = PersistFlag.Persist_And_Count)
public class UserCardMessageContent extends MessageContent {

    public String content;

    public UserCardMessageContent() {
    }

    @Override
    public MessagePayload encode() {
        MessagePayload payload = new MessagePayload();
        try {
            payload.contentType = ContentType_UserCard;
            payload.content = content;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payload;
    }

    @Override
    public void decode(MessagePayload payload) {
        try {
            content = payload.content;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String digest(Message message) {
        return "[个人名片]";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(content);
    }

    protected UserCardMessageContent(Parcel in) {
        content = in.readString();
    }

    public static final Creator<UserCardMessageContent> CREATOR = new Creator<UserCardMessageContent>() {
        @Override
        public UserCardMessageContent createFromParcel(Parcel source) {
            return new UserCardMessageContent(source);
        }

        @Override
        public UserCardMessageContent[] newArray(int size) {
            return new UserCardMessageContent[size];
        }
    };

}
